package com.hzit.bj1804.dianordermanagementwutongservice.controller;


import com.github.pagehelper.PageInfo;
import com.hzit.bj1804.dian.entity.Orderinfo;
import com.hzit.bj1804.dian.entity.Productinfo;
import com.hzit.bj1804.dian.vo.OrderdetailsOrderinfoProductinfo;
import com.hzit.bj1804.dian.vo.OrderinfoMemberpay;
import com.hzit.bj1804.dian.vo.PageRequest;
import com.hzit.bj1804.dianordermanagementwutongservice.service.OrderManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class OrderManagementController {
    @Autowired
    private OrderManagementService orderManagementService;
    //显示所有订单表中的订单数据
    @RequestMapping("allList")
    @ResponseBody
    public Object one(@RequestBody PageRequest pageRequest){
        PageInfo<OrderdetailsOrderinfoProductinfo> alls = orderManagementService.selectAlls(pageRequest);
        return alls;
    }

    //下单时间查询订单
    @RequestMapping("time")
    @ResponseBody
    public Object two(@RequestBody PageRequest pageRequest,@RequestParam("ordertime") String ordertime){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date parse =null;
        try {
             parse = format.parse(ordertime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        PageInfo<Orderinfo> info = orderManagementService.selectTimes(pageRequest, parse);
        return info;
    }

    //根据会员名称搜索订单
    @RequestMapping("cardholdername")
    @ResponseBody
    public Object three(@RequestParam("cardholdername") String cardholdername){
        List<OrderinfoMemberpay> list = orderManagementService.selectCardholdername(cardholdername);
        return list;
    }

    //修改订单状态
    @RequestMapping("stutes")
    @ResponseBody
    public Object four(@RequestBody Orderinfo orderinfo){
        int i = orderManagementService.updatestatues(orderinfo);
        return i;
    }
    //根据id查询商品信息
    @RequestMapping("shangping")
    @ResponseBody
    public Object five(@RequestParam("productid") int productid){
        Productinfo selectshangping = orderManagementService.selectshangping(productid);
        return selectshangping;
    }
    //查询所有商品信息
    @RequestMapping("shangpinAll")
    @ResponseBody
    public Object six(){
        List<Productinfo> productinfos = orderManagementService.selectAlls();
        return productinfos;
    }
    //根据id查询订单三表联合信息
    @RequestMapping("selectByIdXinXi")
    @ResponseBody
    public Object seven(@RequestBody PageRequest pageRequest, @RequestParam("orderid") int orderid){
        System.out.println(pageRequest+"           " +orderid);
        PageInfo<OrderdetailsOrderinfoProductinfo> idAlls = orderManagementService.selectByIdAlls(pageRequest, orderid);
        System.out.println(idAlls);
        return idAlls;
    }
}
